 package uk.co.mmscomputing.device.twain;
 
 import java.io.PrintStream;
 import java.util.Vector;
 
 public class TwainExtImageInfo
   implements TwainConstants
 {
   TwainSource source;
   byte[] buf;
   int[] attributes;
   Vector extInfos;
 
   public TwainExtImageInfo(TwainSource paramTwainSource, int paramInt)
   {
     this.source = paramTwainSource;
     this.attributes = new int[1];
     this.attributes[0] = paramInt;
     initBuf();
   }
 
   public TwainExtImageInfo(TwainSource paramTwainSource, int[] paramArrayOfInt) {
     this.source = paramTwainSource;
     this.attributes = paramArrayOfInt;
     initBuf();
   }
 
   private void initBuf() {
     int i = this.attributes.length;
 
     this.buf = new byte[4 + i * 12];
 
     jtwain.setINT32(this.buf, 0, this.attributes.length);
     int j = 0; for (int k = 4; j < i; j++) {
       jtwain.setINT16(this.buf, k, this.attributes[j]); k += 2;
       jtwain.setINT16(this.buf, k, 0); k += 2;
       jtwain.setINT16(this.buf, k, 0); k += 2;
       jtwain.setINT16(this.buf, k, 0); k += 2;
       jtwain.setINT32(this.buf, k, 0); k += 4;
     }
   }
 
   public void get() throws TwainIOException {
     this.source.call(2, 267, 1, this.buf);
   }
   public Object getInfo() throws TwainIOException {
     return getInfo(this.attributes[0]);
   }
   public Object getInfo(int paramInt) throws TwainIOException {
     int i = 0;
     int j = this.attributes.length;
     while ((i < j) && 
       (this.attributes[i] != paramInt)) {
       i++;
     }
 
     if (i == j) return null;
     int k = 4 + i * 12;
     int m = jtwain.getINT16(this.buf, k + 6);
     if (m != 0) throw new TwainFailureException(m);
     int n = jtwain.getINT16(this.buf, k + 2);
     int i1 = jtwain.getINT16(this.buf, k + 4);
     switch (n) {
     case 5:
       if (i1 == 1) {
         return new Integer(jtwain.getINT16(this.buf, k + 8));
       }
 
       break;
     }
 
     System.err.println(getClass().getName() + ".getInfo:\n\tDon't support type = " + n + " yet.");
 
     return null;
   }
 
   public String toString() {
     String str = "TwainExtImageInfo\n";
 
     int i = this.attributes.length;
     int j = 0; for (int k = 4; j < i; j++) {
       str = str + "InfoID = 0x" + Integer.toHexString(jtwain.getINT16(this.buf, k)) + "\n"; k += 2;
       str = str + "ItemType = " + jtwain.getINT16(this.buf, k) + "\n"; k += 2;
       str = str + "NumItems = " + jtwain.getINT16(this.buf, k) + "\n"; k += 2;
       str = str + "CondCode = " + jtwain.getINT16(this.buf, k) + "\n"; k += 2;
       str = str + "Item = " + jtwain.getINT32(this.buf, k) + "\n"; k += 4;
     }
     return str;
   }
 }

